﻿using LiveChartsCore.SkiaSharpView;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 基于WPF的电缆采样数据分析系统.Models;
using 基于WPF的电缆采样数据分析系统.Models.Enums;
using 基于WPF的电缆采样数据分析系统.Models.Task;
using 基于WPF的电缆采样数据分析系统.Service;
using 基于WPF的电缆采样数据分析系统.Tools.LangugeTool;

namespace 基于WPF的电缆采样数据分析系统.ViewModels.TDRWork.TaskPage
{
    public class TaskPageInfoUCViewModel : BindableBase, IDialogHostAware
    {
        // 单例
        public static TaskPageInfoUCViewModel Instance = new TaskPageInfoUCViewModel();

        // 主机名
        private const string DialogHostName = "RootDialog";

        #region 确定
        /// <summary>
        /// 确定命令 
        /// </summary>
        public DelegateCommand SaveCommand { get; set; }

        /// <summary>
        /// 确定方法
        /// </summary>
        private void SaveFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogParameters paras = new DialogParameters();
                TaskDataInfo task = new TaskDataInfo();
                task.DescriptionInfo = TaskContent;
                task.ChannelConfig = (PassageType)CurrentChannelIndex;
                ChannelArgument XchannelArgument = new ChannelArgument();
                ChannelArgument YchannelArgument = new ChannelArgument();
                XchannelArgument.AxisOrigin = XAxisStartPoint;
                XchannelArgument.AxisEndPoint = XAxisEndPoint;
                XchannelArgument.AxisScale = XAxisScale;
                YchannelArgument.AxisOrigin = YAxisStartPoint;
                YchannelArgument.AxisEndPoint = YAxisEndPoint;
                YchannelArgument.AxisScale = YAxisScale;
                task.HorizontalArgument = XchannelArgument;
                task.VerticalArgument = YchannelArgument;
                task.UpdateUser = GlobalVariableEdit.CurrentUserInfo.Uid;
                task.CreateTime = DateTime.Now;
                task.UpdateTime = DateTime.Now;
                task.XAxisTranslation = XAxisTranslation;
                task.YAxisTranslation = YAxisTranslation;
                paras.Add("Task", task);

                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.Yes, paras));

            }
        }
        #endregion


        #region 取消
        /// <summary>
        /// 取消命令
        /// </summary>
        public DelegateCommand CancelCommand { get; set; }

        /// <summary>
        /// 取消方法
        /// </summary>
        private void CancelFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No));
            }
        }
        #endregion


        /// <summary>
        /// 打开过程中
        /// </summary>
        /// <param name="parameters"></param>
        public void OnDialogOpening(IDialogParameters parameters)
        {
            PageTitle = parameters.GetValue<string>("pattern");
            TaskContent = parameters.GetValue<string>("TaskContent");
            CurrentChannelIndex = (int)parameters.GetValue<PassageType>("CurrentChannelIndex");
            XAxisStartPoint = parameters.GetValue<float>("XAxisStartPoint");
            XAxisEndPoint = parameters.GetValue<float>("XAxisEndPoint");
            XAxisScale = parameters.GetValue<float>("XAxisScale");
            YAxisStartPoint = parameters.GetValue<float>("YAxisStartPoint");
            YAxisEndPoint = parameters.GetValue<float>("YAxisEndPoint");
            YAxisScale = parameters.GetValue<float>("YAxisScale");
            XAxisTranslation = parameters.GetValue<float>("XAxisTranslation");
            YAxisTranslation = parameters.GetValue<float>("YAxisTranslation");
        }

        /// <summary>
        /// 构造器
        /// </summary>
        public TaskPageInfoUCViewModel()
        {
            // 绑定确定和取消命令
            SaveCommand = new DelegateCommand(SaveFun);
            CancelCommand = new DelegateCommand(CancelFun);

            // 初始化通道类型数据
            InitChannelTypeList();

            // 绑定X轴起点减少
            XASP_ReduceCmm = new DelegateCommand(XASP_ReduceFun);
            // 绑定X轴起点增加
            XASP_AddCmm = new DelegateCommand(XASP_AddFun);

            // 绑定X轴终点减少
            XAEP_ReduceCmm = new DelegateCommand(XAEP_ReduceFun);
            // 绑定X轴终点增加
            XAEP_AddCmm = new DelegateCommand(XAEP_AddFun);

            // 绑定X轴刻度递减
            XAS_ReduceCmm = new DelegateCommand(XAS_ReduceFun);
            // 绑定X轴刻度递增
            XAS_AddCmm = new DelegateCommand(XAS_AddFun);

            // 绑定Y轴起点减少
            YASP_ReduceCmm = new DelegateCommand(YASP_ReduceFun);
            // 绑定Y轴起点增加
            YASP_AddCmm = new DelegateCommand(YASP_AddFun);

            // 绑定Y轴终点减少
            YAEP_ReduceCmm = new DelegateCommand(YAEP_ReduceFun);
            // 绑定Y轴终点增加
            YAEP_AddCmm = new DelegateCommand(YAEP_AddFun);

            // 绑定Y轴刻度递减
            YAS_ReduceCmm = new DelegateCommand(YAS_ReduceFun);
            // 绑定Y轴刻度递增
            YAS_AddCmm = new DelegateCommand(YAS_AddFun);

            // 绑定波形向左平移
            XAT_ReduceCmm = new DelegateCommand(XAT_ReduceFun);
            // 绑定波形向右平移
            XAT_AddCmm = new DelegateCommand(XAT_AddFun);

            // 绑定波形向下平移
            YAT_ReduceCmm = new DelegateCommand(YAT_ReduceFun);
            // 绑定波形向上平移
            YAT_AddCmm = new DelegateCommand(YAT_AddFun);
        }

        #region 通道类型
        /// <summary>
        /// 通道改变命令
        /// </summary>
        public DelegateCommand<int?> ChannelChangedCmm { get; set; }

        /// <summary>
        /// 通道类型
        /// </summary>
        private List<TypeInfo> _ChannelTypeList;

        /// <summary>
        /// 通道类型
        /// </summary>
        public List<TypeInfo> ChannelTypeList
        {
            get { return _ChannelTypeList; }
            set
            {
                _ChannelTypeList = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 当前通道值
        /// </summary>
        private PassageType _CurrentChannelValue;

        /// <summary>
        /// 当前通道值
        /// </summary>
        public PassageType CurrentChannelValue
        {
            get { return _CurrentChannelValue; }
            set
            {
                _CurrentChannelValue = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 当前通道索引
        /// </summary>
        private int _CurrentChannelIndex;

        /// <summary>
        /// 当前通道索引
        /// </summary>
        public int CurrentChannelIndex
        {
            get { return _CurrentChannelIndex; }
            set { 
                _CurrentChannelIndex = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 初始化通道类型数据
        /// </summary>
        private void InitChannelTypeList()
        {
            ChannelTypeList = new List<TypeInfo>();
            ChannelTypeList.Add(new TypeInfo() { ShowContent = "通道一", Value = 0 });
            ChannelTypeList.Add(new TypeInfo() { ShowContent = "通道二", Value = 1 });
            ChannelTypeList.Add(new TypeInfo() { ShowContent = "通道三", Value = 2 });
        }

        #endregion


        #region 页面信息
        /// <summary>
        /// 弹窗标题
        /// </summary>
        private string _PageTitle;

        /// <summary>
        /// 弹窗标题
        /// </summary>
        public string PageTitle
        {
            get { return _PageTitle; }
            set { 
                _PageTitle = value;
                RaisePropertyChanged();
            }
        }


        #endregion


        #region 描述
        /// <summary>
        /// 描述
        /// </summary>
        private string _TaskContent;

        /// <summary>
        /// 描述
        /// </summary>
        public string TaskContent
        {
            get { return _TaskContent; }
            set { 
                _TaskContent = value;
                RaisePropertyChanged();
            }
        }

        #endregion


        #region 水平参数

        /// <summary>
        /// X轴起点
        /// </summary>
        private float _XAxisStartPoint;

        /// <summary>
        /// X轴起点
        /// </summary>
        public float XAxisStartPoint
        {
            get { return _XAxisStartPoint; }
            set {
                _XAxisStartPoint = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// X轴终点
        /// </summary>
        private float _XAxisEndPoint;

        /// <summary>
        /// X轴终点
        /// </summary>
        public float XAxisEndPoint
        {
            get { return _XAxisEndPoint; }
            set { 
                _XAxisEndPoint = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// X轴刻度
        /// </summary>
        private float _XAxisScale;

        /// <summary>
        /// X轴刻度
        /// </summary>
        public float XAxisScale
        {
            get { return _XAxisScale; }
            set { 
                _XAxisScale = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// X轴平移
        /// </summary>
        private float _XAxisTranslation;

        /// <summary>
        /// X轴平移
        /// </summary>
        public float XAxisTranslation
        {
            get { return _XAxisTranslation; }
            set { 
                _XAxisTranslation = value;
                RaisePropertyChanged();
            }
        }


        #endregion


        #region 垂直参数
        /// <summary>
        /// Y轴起点
        /// </summary>
        private float _YAxisStartPoint;

        /// <summary>
        /// Y轴起点
        /// </summary>
        public float YAxisStartPoint
        {
            get { return _YAxisStartPoint; }
            set {
                _YAxisStartPoint = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// Y轴终点
        /// </summary>
        private float _YAxisEndPoint;

        /// <summary>
        /// Y轴终点
        /// </summary>
        public float YAxisEndPoint
        {
            get { return _YAxisEndPoint; }
            set { 
                _YAxisEndPoint = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// Y轴刻度
        /// </summary>
        private float _YAxisScale;

        /// <summary>
        /// Y轴刻度
        /// </summary>
        public float YAxisScale
        {
            get { return _YAxisScale; }
            set { 
                _YAxisScale = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// Y轴平移
        /// </summary>
        private float _YAxisTranslation;

        /// <summary>
        /// Y轴平移
        /// </summary>
        public float YAxisTranslation
        {
            get { return _YAxisTranslation; }
            set { 
                _YAxisTranslation = value;
                RaisePropertyChanged();
            }
        }


        #endregion


        #region 计算器计算值
        /// <summary>
        /// 计算器计算值
        /// </summary>
        private string _ComputeValue = "213";

        /// <summary>
        /// 计算器计算值
        /// </summary>
        public string ComputeValue
        {
            get { return _ComputeValue; }
            set { 
                _ComputeValue = value;
                RaisePropertyChanged();
            }
        }


        #endregion


        #region 计算器单位值
        /// <summary>
        /// 计算器单位值
        /// </summary>
        private string _UnitValue;

        /// <summary>
        /// 计算器单位值
        /// </summary>
        public string UnitValue
        {
            get { return _UnitValue; }
            set { 
                _UnitValue = value;
                RaisePropertyChanged();
            }
        }
        #endregion


        #region X轴起点
        /// <summary>
        /// X轴起点减少
        /// </summary>
        public DelegateCommand XASP_ReduceCmm { get; set; }

        /// <summary>
        /// X轴起点减少
        /// </summary>
        private void XASP_ReduceFun()
        {
            XAxisStartPoint -= 10;
        }


        /// <summary>
        /// X轴起点增加
        /// </summary>
        public DelegateCommand XASP_AddCmm { get; set; }

        /// <summary>
        /// X轴起点增加
        /// </summary>
        private void XASP_AddFun()
        {
            XAxisStartPoint += 10;
        }
        #endregion


        #region X轴终点
        /// <summary>
        /// X轴终点减少
        /// </summary>
        public DelegateCommand XAEP_ReduceCmm { get; set; }

        /// <summary>
        /// X轴终点减少
        /// </summary>
        private void XAEP_ReduceFun()
        {
            XAxisEndPoint -= 10;
        }


        /// <summary>
        /// X轴终点增加
        /// </summary>
        public DelegateCommand XAEP_AddCmm { get; set; }

        /// <summary>
        /// X轴终点增加
        /// </summary>
        private void XAEP_AddFun()
        {
            XAxisEndPoint += 10;
        }

        #endregion


        #region X轴刻度
        /// <summary>
        /// X轴刻度递减
        /// </summary>
        public DelegateCommand XAS_ReduceCmm { get; set; }

        /// <summary>
        /// X轴刻度递减
        /// </summary>
        private void XAS_ReduceFun()
        {
            XAxisScale /= 2;
        }


        /// <summary>
        /// X轴刻度递增
        /// </summary>
        public DelegateCommand XAS_AddCmm { get; set; }

        /// <summary>
        /// X轴刻度递增
        /// </summary>
        private void XAS_AddFun()
        {
            XAxisScale *= 2;
        }

        #endregion


        #region X轴平移
        /// <summary>
        /// 波形向左平移
        /// </summary>
        public DelegateCommand XAT_ReduceCmm { get; set; }

        /// <summary>
        /// 波形向左平移
        /// </summary>
        private void XAT_ReduceFun()
        {
            XAxisTranslation -= 10;
        }

        /// <summary>
        /// 波形向右平移
        /// </summary>
        public DelegateCommand XAT_AddCmm { get; set; }

        /// <summary>
        /// 波形向右平移
        /// </summary>
        private void XAT_AddFun()
        {
            XAxisTranslation += 10;
        }

        #endregion


        #region Y轴起点
        /// <summary>
        /// Y轴起点减少
        /// </summary>
        public DelegateCommand YASP_ReduceCmm { get; set; }

        /// <summary>
        /// Y轴起点减少
        /// </summary>
        private void YASP_ReduceFun()
        {
            YAxisStartPoint -= 10;
        }


        /// <summary>
        /// Y轴起点增加
        /// </summary>
        public DelegateCommand YASP_AddCmm { get; set; }

        /// <summary>
        /// Y轴起点增加
        /// </summary>
        private void YASP_AddFun()
        {
            YAxisStartPoint += 10;
        }

        #endregion


        #region Y轴终点
        /// <summary>
        /// Y轴终点减少
        /// </summary>
        public DelegateCommand YAEP_ReduceCmm { get; set; }

        /// <summary>
        /// Y轴终点减少
        /// </summary>
        private void YAEP_ReduceFun()
        {
            YAxisEndPoint -= 10;
        }


        /// <summary>
        /// Y轴终点增加
        /// </summary>
        public DelegateCommand YAEP_AddCmm { get; set; }

        /// <summary>
        /// Y轴终点增加
        /// </summary>
        private void YAEP_AddFun()
        {
            YAxisEndPoint += 10;
        }

        #endregion


        #region Y轴刻度
        /// <summary>
        ///Y轴刻度递减
        /// </summary>
        public DelegateCommand YAS_ReduceCmm { get; set; }

        /// <summary>
        /// Y轴刻度递减
        /// </summary>
        private void YAS_ReduceFun()
        {
            YAxisScale /= 2;
        }


        /// <summary>
        /// Y轴刻度递增
        /// </summary>
        public DelegateCommand YAS_AddCmm { get; set; }

        /// <summary>
        /// Y轴刻度递增
        /// </summary>
        private void YAS_AddFun()
        {
            YAxisScale *= 2;
        }

        #endregion


        #region Y轴平移

        /// <summary>
        /// 波形向下平移
        /// </summary>
        public DelegateCommand YAT_ReduceCmm { get; set; }

        /// <summary>
        /// 波形向下平移
        /// </summary>
        private void YAT_ReduceFun()
        {
            YAxisTranslation -= 10;
        }

        /// <summary>
        /// 波形向上平移
        /// </summary>
        public DelegateCommand YAT_AddCmm { get; set; }

        /// <summary>
        /// 波形向上平移
        /// </summary>
        private void YAT_AddFun()
        {
            YAxisTranslation += 10;
        }

        #endregion
    }
}
